<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/gui/widgets/qspinbox.cpp -->
<head>
  <title>Qt 4.3: QSpinBox Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QSpinBox Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1>
<p>The QSpinBox class provides a spin box widget. <a href="#details">More...</a></p>
<pre> #include &lt;QSpinBox&gt;</pre><p>Inherits <a href="qabstractspinbox.html">QAbstractSpinBox</a>.</p>
<ul>
<li><a href="qspinbox-members.html">List of all members, including inherited members</a></li>
<li><a href="qspinbox-qt3.html">Qt 3 support members</a></li>
</ul>
<a name="properties"></a>
<h3>Properties</h3>
<p><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td width="45%" valign="top"><ul>
<li><div class="fn"/><b><a href="qspinbox.html#cleanText-prop">cleanText</a></b> : const QString</li>
<li><div class="fn"/><b><a href="qspinbox.html#maximum-prop">maximum</a></b> : int</li>
<li><div class="fn"/><b><a href="qspinbox.html#minimum-prop">minimum</a></b> : int</li>
<li><div class="fn"/><b><a href="qspinbox.html#prefix-prop">prefix</a></b> : QString</li>
</ul></td><td valign="top"><ul>
<li><div class="fn"/><b><a href="qspinbox.html#singleStep-prop">singleStep</a></b> : int</li>
<li><div class="fn"/><b><a href="qspinbox.html#suffix-prop">suffix</a></b> : QString</li>
<li><div class="fn"/><b><a href="qspinbox.html#value-prop">value</a></b> : int</li>
</ul>
</td></tr>
</table></p>
<ul>
<li><div class="fn"/>11 properties inherited from <a href="qabstractspinbox.html#properties">QAbstractSpinBox</a></li>
<li><div class="fn"/>56 properties inherited from <a href="qwidget.html#properties">QWidget</a></li>
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qspinbox.html#QSpinBox">QSpinBox</a></b> ( QWidget * <i>parent</i> = 0 )</li>
<li><div class="fn"/>QString <b><a href="qspinbox.html#cleanText-prop">cleanText</a></b> () const</li>
<li><div class="fn"/>int <b><a href="qspinbox.html#maximum-prop">maximum</a></b> () const</li>
<li><div class="fn"/>int <b><a href="qspinbox.html#minimum-prop">minimum</a></b> () const</li>
<li><div class="fn"/>QString <b><a href="qspinbox.html#prefix-prop">prefix</a></b> () const</li>
<li><div class="fn"/>void <b><a href="qspinbox.html#maximum-prop">setMaximum</a></b> ( int <i>max</i> )</li>
<li><div class="fn"/>void <b><a href="qspinbox.html#minimum-prop">setMinimum</a></b> ( int <i>min</i> )</li>
<li><div class="fn"/>void <b><a href="qspinbox.html#prefix-prop">setPrefix</a></b> ( const QString &amp; <i>prefix</i> )</li>
<li><div class="fn"/>void <b><a href="qspinbox.html#setRange">setRange</a></b> ( int <i>minimum</i>, int <i>maximum</i> )</li>
<li><div class="fn"/>void <b><a href="qspinbox.html#singleStep-prop">setSingleStep</a></b> ( int <i>val</i> )</li>
<li><div class="fn"/>void <b><a href="qspinbox.html#suffix-prop">setSuffix</a></b> ( const QString &amp; <i>suffix</i> )</li>
<li><div class="fn"/>int <b><a href="qspinbox.html#singleStep-prop">singleStep</a></b> () const</li>
<li><div class="fn"/>QString <b><a href="qspinbox.html#suffix-prop">suffix</a></b> () const</li>
<li><div class="fn"/>int <b><a href="qspinbox.html#value-prop">value</a></b> () const</li>
</ul>
<ul>
<li><div class="fn"/>24 public functions inherited from <a href="qabstractspinbox.html#public-functions">QAbstractSpinBox</a></li>
<li><div class="fn"/>201 public functions inherited from <a href="qwidget.html#public-functions">QWidget</a></li>
<li><div class="fn"/>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
<li><div class="fn"/>12 public functions inherited from <a href="qpaintdevice.html#public-functions">QPaintDevice</a></li>
</ul>
<a name="public-slots"></a>
<h3>Public Slots</h3>
<ul>
<li><div class="fn"/>void <b><a href="qspinbox.html#value-prop">setValue</a></b> ( int <i>val</i> )</li>
</ul>
<ul>
<li><div class="fn"/>4 public slots inherited from <a href="qabstractspinbox.html#public-slots">QAbstractSpinBox</a></li>
<li><div class="fn"/>19 public slots inherited from <a href="qwidget.html#public-slots">QWidget</a></li>
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
</ul>
<a name="signals"></a>
<h3>Signals</h3>
<ul>
<li><div class="fn"/>void <b><a href="qspinbox.html#valueChanged">valueChanged</a></b> ( int <i>i</i> )</li>
<li><div class="fn"/>void <b><a href="qspinbox.html#valueChanged-2">valueChanged</a></b> ( const QString &amp; <i>text</i> )</li>
</ul>
<ul>
<li><div class="fn"/>1 signal inherited from <a href="qabstractspinbox.html#signals">QAbstractSpinBox</a></li>
<li><div class="fn"/>1 signal inherited from <a href="qwidget.html#signals">QWidget</a></li>
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
</ul>
<a name="protected-functions"></a>
<h3>Protected Functions</h3>
<ul>
<li><div class="fn"/>virtual QString <b><a href="qspinbox.html#textFromValue">textFromValue</a></b> ( int <i>value</i> ) const</li>
<li><div class="fn"/>virtual int <b><a href="qspinbox.html#valueFromText">valueFromText</a></b> ( const QString &amp; <i>text</i> ) const</li>
</ul>
<ul>
<li><div class="fn"/>4 protected functions inherited from <a href="qabstractspinbox.html#protected-functions">QAbstractSpinBox</a></li>
<li><div class="fn"/>38 protected functions inherited from <a href="qwidget.html#protected-functions">QWidget</a></li>
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
<li><div class="fn"/>1 protected function inherited from <a href="qpaintdevice.html#protected-functions">QPaintDevice</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"/>4 static public members inherited from <a href="qwidget.html#static-public-members">QWidget</a></li>
<li><div class="fn"/>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li><div class="fn"/>1 protected slot inherited from <a href="qwidget.html#protected-slots">QWidget</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QSpinBox class provides a spin box widget.</p>
<p>QSpinBox is designed to handle integers and discrete sets of values (e.g&#x2e;, month names); use <a href="qdoublespinbox.html">QDoubleSpinBox</a> for floating point values.</p>
<p>QSpinBox allows the user to choose a value by clicking the up/down buttons or pressing up/down on the keyboard to increase/decrease the value currently displayed. The user can also type the value in manually. The spin box supports integer values but can be extended to use different strings with <a href="qabstractspinbox.html#validate">validate</a>(), <a href="qspinbox.html#textFromValue">textFromValue</a>() and <a href="qspinbox.html#valueFromText">valueFromText</a>().</p>
<p>Every time the value changes QSpinBox emits the <a href="qspinbox.html#valueChanged">valueChanged</a>() signals. The current value can be fetched with <a href="qspinbox.html#value-prop">value</a>() and set with <a href="qspinbox.html#value-prop">setValue</a>().</p>
<p>Clicking the up/down buttons or using the keyboard accelerator's up and down arrows will increase or decrease the current value in steps of size <a href="qspinbox.html#singleStep-prop">singleStep</a>(). If you want to change this behaviour you can reimplement the virtual function <a href="qabstractspinbox.html#stepBy">stepBy</a>(). The minimum and maximum value and the step size can be set using one of the constructors, and can be changed later with <a href="qspinbox.html#minimum-prop">setMinimum</a>(), <a href="qspinbox.html#maximum-prop">setMaximum</a>() and <a href="qspinbox.html#singleStep-prop">setSingleStep</a>().</p>
<p>Most spin boxes are directional, but QSpinBox can also operate as a circular spin box, i.e&#x2e; if the range is 0-99 and the current value is 99, clicking &quot;up&quot; will give 0 if <a href="qabstractspinbox.html#wrapping-prop">wrapping</a>() is set to true. Use <a href="qabstractspinbox.html#wrapping-prop">setWrapping</a>() if you want circular behavior.</p>
<p>The displayed value can be prepended and appended with arbitrary strings indicating, for example, currency or the unit of measurement. See <a href="qspinbox.html#prefix-prop">setPrefix</a>() and <a href="qspinbox.html#suffix-prop">setSuffix</a>(). The text in the spin box is retrieved with <a href="qabstractspinbox.html#text-prop">text</a>() (which includes any <a href="qspinbox.html#prefix-prop">prefix</a>() and <a href="qspinbox.html#suffix-prop">suffix</a>()), or with <a href="qspinbox.html#cleanText-prop">cleanText</a>() (which has no <a href="qspinbox.html#prefix-prop">prefix</a>(), no <a href="qspinbox.html#suffix-prop">suffix</a>() and no leading or trailing whitespace).</p>
<p>It is often desirable to give the user a special (often default) choice in addition to the range of numeric values. See <a href="qabstractspinbox.html#specialValueText-prop">setSpecialValueText</a>() for how to do this with QSpinBox.</p>
<p><table width="100%" align="center" cellpadding="2" cellspacing="1" border="0">
<tr valign="top" class="odd"><td><img src="images/windowsxp-spinbox.png" alt="Screenshot of a Windows XP spin box" /></td><td>A spin box shown in the <a href="gallery-windowsxp.html">Windows XP widget style</a>.</td></tr>
<tr valign="top" class="even"><td><img src="images/plastique-spinbox.png" alt="Screenshot of a Plastique spin box" /></td><td>A spin box shown in the <a href="gallery-plastique.html">Plastique widget style</a>.</td></tr>
<tr valign="top" class="odd"><td><img src="images/macintosh-spinbox.png" alt="Screenshot of a Macintosh spin box" /></td><td>A spin box shown in the <a href="gallery-macintosh.html">Macintosh widget style</a>.</td></tr>
</table></p>
<a name="subclassing-qspinbox"></a>
<h3>Subclassing QSpinBox</h3>
<p>If using <a href="qspinbox.html#prefix-prop">prefix</a>(), <a href="qspinbox.html#suffix-prop">suffix</a>(), and <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>() don't provide enough control, you subclass QSpinBox and reimplement <a href="qspinbox.html#valueFromText">valueFromText</a>() and <a href="qspinbox.html#textFromValue">textFromValue</a>(). For example, here's the code for a custom spin box that allows the user to enter icon sizes (e.g&#x2e;, &quot;32 x 32&quot;):</p>
<pre> int IconSizeSpinBox::valueFromText(const QString &amp;text) const
 {
     QRegExp regExp(tr(&quot;(\\d+)(\\s*[xx]\\s*\\d+)?&quot;));

     if (regExp.exactMatch(text)) {
         return regExp.cap(1).toInt();
     } else {
         return 0;
     }
 }

 QString IconSizeSpinBox::textFromValue(int value) const
 {
     return tr(&quot;%1 x %1&quot;).arg(value);
 }</pre>
<p>See the <a href="widgets-icons.html">Icons</a> example for the full source code.</p>
<p>See also <a href="qdoublespinbox.html">QDoubleSpinBox</a>, <a href="qdatetimeedit.html">QDateTimeEdit</a>, <a href="qslider.html">QSlider</a>, and <a href="widgets-spinboxes.html">Spin Boxes Example</a>.</p>
<hr />
<h2>Property Documentation</h2>
<h3 class="fn"><a name="cleanText-prop"></a>cleanText : const <a href="qstring.html">QString</a></h3>
<p>This property holds the text of the spin box excluding any prefix, suffix, or leading or trailing whitespace.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>QString cleanText () const</b></li>
</ul>
<p>See also <a href="qabstractspinbox.html#text-prop">text</a>, <a href="qspinbox.html#prefix-prop">QSpinBox::prefix</a>, and <a href="qspinbox.html#suffix-prop">QSpinBox::suffix</a>.</p>
<h3 class="fn"><a name="maximum-prop"></a>maximum : int</h3>
<p>This property holds the maximum value of the spin box.</p>
<p>When setting this property the <a href="qspinbox.html#minimum-prop">minimum</a> is adjusted if necessary, to ensure that the range remains valid.</p>
<p>The default maximum value is 99.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>int maximum () const</b></li>
<li><div class="fn"/><b>void setMaximum ( int <i>max</i> )</b></li>
</ul>
<p>See also <a href="qspinbox.html#setRange">setRange</a>() and <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>.</p>
<h3 class="fn"><a name="minimum-prop"></a>minimum : int</h3>
<p>This property holds the minimum value of the spin box.</p>
<p>When setting this property the <a href="qspinbox.html#maximum-prop">maximum</a> is adjusted if necessary to ensure that the range remains valid.</p>
<p>The default minimum value is 0.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>int minimum () const</b></li>
<li><div class="fn"/><b>void setMinimum ( int <i>min</i> )</b></li>
</ul>
<p>See also <a href="qspinbox.html#setRange">setRange</a>() and <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>.</p>
<h3 class="fn"><a name="prefix-prop"></a>prefix : <a href="qstring.html">QString</a></h3>
<p>This property holds the spin box's prefix.</p>
<p>The prefix is prepended to the start of the displayed value. Typical use is to display a unit of measurement or a currency symbol. For example:</p>
<pre> sb-&gt;setPrefix(&quot;$&quot;);</pre>
<p>To turn off the prefix display, set this property to an empty string. The default is no prefix. The prefix is not displayed when <a href="qspinbox.html#value-prop">value</a>() == <a href="qspinbox.html#minimum-prop">minimum</a>() and <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>() is set.</p>
<p>If no prefix is set, prefix() returns an empty string.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>QString prefix () const</b></li>
<li><div class="fn"/><b>void setPrefix ( const QString &amp; <i>prefix</i> )</b></li>
</ul>
<p>See also <a href="qspinbox.html#suffix-prop">suffix</a>(), <a href="qspinbox.html#suffix-prop">setSuffix</a>(), <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>(), and <a href="qabstractspinbox.html#specialValueText-prop">setSpecialValueText</a>().</p>
<h3 class="fn"><a name="singleStep-prop"></a>singleStep : int</h3>
<p>This property holds the step value.</p>
<p>When the user uses the arrows to change the spin box's value the value will be incremented/decremented by the amount of the singleStep. The default value is 1. Setting a singleStep value of less than 0 does nothing.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>int singleStep () const</b></li>
<li><div class="fn"/><b>void setSingleStep ( int <i>val</i> )</b></li>
</ul>
<h3 class="fn"><a name="suffix-prop"></a>suffix : <a href="qstring.html">QString</a></h3>
<p>This property holds the suffix of the spin box.</p>
<p>The suffix is appended to the end of the displayed value. Typical use is to display a unit of measurement or a currency symbol. For example:</p>
<pre> sb-&gt;setSuffix(&quot; km&quot;);</pre>
<p>To turn off the suffix display, set this property to an empty string. The default is no suffix. The suffix is not displayed for the <a href="qspinbox.html#minimum-prop">minimum</a>() if <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>() is set.</p>
<p>If no suffix is set, suffix() returns an empty string.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>QString suffix () const</b></li>
<li><div class="fn"/><b>void setSuffix ( const QString &amp; <i>suffix</i> )</b></li>
</ul>
<p>See also <a href="qspinbox.html#prefix-prop">prefix</a>(), <a href="qspinbox.html#prefix-prop">setPrefix</a>(), <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>(), and <a href="qabstractspinbox.html#specialValueText-prop">setSpecialValueText</a>().</p>
<h3 class="fn"><a name="value-prop"></a>value : int</h3>
<p>This property holds the value of the spin box.</p>
<p>setValue() will emit <a href="qspinbox.html#valueChanged">valueChanged</a>() if the new value is different from the old one.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>int value () const</b></li>
<li><div class="fn"/><b>void setValue ( int <i>val</i> )</b></li>
</ul>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QSpinBox"></a>QSpinBox::QSpinBox ( <a href="qwidget.html">QWidget</a> * <i>parent</i> = 0 )</h3>
<p>Constructs a spin box with 0 as minimum value and 99 as maximum value, a step value of 1. The value is initially set to 0. It is parented to <i>parent</i>.</p>
<p>See also <a href="qspinbox.html#minimum-prop">setMinimum</a>(), <a href="qspinbox.html#maximum-prop">setMaximum</a>(), and <a href="qspinbox.html#singleStep-prop">setSingleStep</a>().</p>
<h3 class="fn"><a name="setRange"></a>void QSpinBox::setRange ( int <i>minimum</i>, int <i>maximum</i> )</h3>
<p>Convenience function to set the <i>minimum</i>, and <i>maximum</i> values with a single function call.</p>
<pre> setRange(minimum, maximum);</pre>
<p>is equivalent to:</p>
<pre> setMinimum(minimum);
 setMaximum(maximum);</pre>
<p>See also <a href="qspinbox.html#minimum-prop">minimum</a> and <a href="qspinbox.html#maximum-prop">maximum</a>.</p>
<h3 class="fn"><a name="textFromValue"></a><a href="qstring.html">QString</a> QSpinBox::textFromValue ( int <i>value</i> ) const&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
<p>This virtual function is used by the spin box whenever it needs to display the given <i>value</i>. The default implementation returns a string containing <i>value</i> printed in the standard way using QLocale().toString(). Reimplementations may return anything. (See the example in the detailed description.)</p>
<p>Note: <a href="qspinbox.html">QSpinBox</a> does not call this function for <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>() and that neither <a href="qspinbox.html#prefix-prop">prefix</a>() nor <a href="qspinbox.html#suffix-prop">suffix</a>() should be included in the return value.</p>
<p>If you reimplement this, you may also need to reimplement <a href="qspinbox.html#valueFromText">valueFromText</a>() and <a href="qabstractspinbox.html#validate">validate</a>()</p>
<p>See also <a href="qspinbox.html#valueFromText">valueFromText</a>() and <a href="qabstractspinbox.html#validate">validate</a>().</p>
<h3 class="fn"><a name="valueChanged"></a>void QSpinBox::valueChanged ( int <i>i</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal is emitted whenever the spin box's value is changed. The new value's integer value is passed in <i>i</i>.</p>
<h3 class="fn"><a name="valueChanged-2"></a>void QSpinBox::valueChanged ( const <a href="qstring.html">QString</a> &amp; <i>text</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>The new value is passed literally in <i>text</i> with no <a href="qspinbox.html#prefix-prop">prefix</a>() or <a href="qspinbox.html#suffix-prop">suffix</a>().</p>
<h3 class="fn"><a name="valueFromText"></a>int QSpinBox::valueFromText ( const <a href="qstring.html">QString</a> &amp; <i>text</i> ) const&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
<p>This virtual function is used by the spin box whenever it needs to interpret <i>text</i> entered by the user as a value.</p>
<p>Subclasses that need to display spin box values in a non-numeric way need to reimplement this function.</p>
<p>Note: <a href="qspinbox.html">QSpinBox</a> handles <a href="qabstractspinbox.html#specialValueText-prop">specialValueText</a>() separately; this function is only concerned with the other values.</p>
<p>See also <a href="qspinbox.html#textFromValue">textFromValue</a>() and <a href="qabstractspinbox.html#validate">validate</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
